---
title: ""
output: pdf_document
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(survey)
library(xtable)

## see PCM_cleaning.R for data cleaning
load("~/Dropbox/Public_Conf_Mil/Data_and_code/clean_data.RData")

## Create weighted survey design object
milconf_design <-
  svydesign(
    id = ~ 1,
    weights = ~ weight,
    data = mil_conf.df
  )
```

```{r echo = FALSE}
prop2_1 <- svytable(~ Q7A+RND_03, design = milconf_design)[1:4]
total2_1 <- sum(prop2_1[1:4])
table2_1 <- prop2_1/total2_1 * 100

prop2_2 <- svytable(~ Q7C+RND_03, design = milconf_design)[1:4]
total2_2 <- sum(prop2_2[1:4])
table2_2 <- prop2_2/total2_2 * 100

prop2_3 <- svytable(~ Q7D+RND_03, design = milconf_design)[1:4]
total2_3 <- sum(prop2_3[1:4])
table2_3 <- prop2_3/total2_3 * 100

prop2_4 <- svytable(~ Q7F+RND_03, design = milconf_design)[1:4]
total2_4 <- sum(prop2_4[1:4])
table2_4 <- prop2_4/total2_4 * 100

prop2_5 <- svytable(~ Q7I+RND_03, design = milconf_design)[1:4]
total2_5 <- sum(prop2_5[1:4])
table2_5 <- prop2_5/total2_5 * 100

table2 <- data.frame(label = c("Active Duty", "Retired", "Not Sure", "Never Heard Of"),
                     Mattis = table2_1,
                     Petraeus = table2_2,
                     Powell = table2_3,
                     Stavridis = table2_4,
                     McRaven = table2_5)

colnames(table2) <- c("", "Mattis", "Petraeus", "Powell", "Stavridis", "McRaven")
tab2 <- xtable(table2)
align(tab2) <- "rrccccc"
digits(tab2) <- c(0,0,1,1,1,1,1)
```

```{r echo = FALSE, results = "asis"}
print(tab2, comment = FALSE, size = "\\large", include.rownames = FALSE)
```

```{r echo = FALSE}
prop3_1 <- svytable(~ Q7B+RND_03, design = milconf_design)[1:4]
total3_1 <- sum(prop3_1[1:4])
table3_1 <- prop3_1/total3_1 * 100

prop3_2 <- svytable(~ Q7E+RND_03, design = milconf_design)[1:4]
total3_2 <- sum(prop3_2[1:4])
table3_2 <- prop3_2/total3_2 * 100

prop3_3 <- svytable(~ Q7G+RND_03, design = milconf_design)[1:4]
total3_3 <- sum(prop3_3[1:4])
table3_3 <- prop3_3/total3_3 * 100

prop3_4 <- svytable(~ Q7H+RND_03, design = milconf_design)[1:4]
total3_4 <- sum(prop3_4[1:4])
table3_4 <- prop3_4/total3_4 * 100

table3 <- data.frame(label = c("Active Duty", "Retired", "Not Sure", "Never Heard Of"),
                     gofo1 = table3_1,
                     gofo2 = table3_2,
                     gofo3 = table3_3,
                     gofo4 = table3_4)

colnames(table3) <- c("", "McMaster", "Goldfein", "Dunford", "Milley")
tab3 <- xtable(table3)
align(tab3) <- "rrcccc"
digits(tab3) <- c(0,0,1,1,1,1)
```

```{r echo = FALSE, results = "asis"}
print(tab3, comment = FALSE, size = "\\large", include.rownames = FALSE)
```

```{r echo = FALSE}
prop4_1 <- svytable(~ Q7A, design = milconf_design)[1:4]
total4_1 <- sum(prop4_1[1:4])
table4_1 <- prop4_1/total4_1 * 100

prop4_2 <- svytable(~ Q7C, design = milconf_design)[1:4]
total4_2 <- sum(prop4_2[1:4])
table4_2 <- prop4_2/total4_2 * 100

prop4_3 <- svytable(~ Q7D, design = milconf_design)[1:4]
total4_3 <- sum(prop4_3[1:4])
table4_3 <- prop4_3/total4_3 * 100

prop4_4 <- svytable(~ Q7F, design = milconf_design)[1:4]
total4_4 <- sum(prop4_4[1:4])
table4_4 <- prop4_4/total4_4 * 100

prop4_5 <- svytable(~ Q7I, design = milconf_design)[1:4]
total4_5 <- sum(prop4_5[1:4])
table4_5 <- prop4_5/total4_5 * 100

table4 <- as.data.frame(Mattis = table4_1,
                        Petraeus = table4_2,
                        Powell = table4_3,
                        Stavridis = table4_4,
                        McRaven = table4_5)

colnames(table4) <- c("", "Mattis", "Petraeus", "Powell", "Stavridis", "McRaven")
tab4 <- xtable(table4)
align(tab4) <- "rrccccc"
digits(tab4) <- c(0,0,1,1,1,1,1)
```

```{r echo = FALSE, results = "asis"}
print(tab4, comment = FALSE, size = "\\large", include.rownames = FALSE)
```

```{r echo = FALSE}
prop5_1 <- svytable(~ Q7B, design = milconf_design)[1:4]
total5_1 <- sum(prop5_1[1:4])
table5_1 <- prop5_1/total5_1 * 100

prop5_2 <- svytable(~ Q7E, design = milconf_design)[1:4]
total5_2 <- sum(prop5_2[1:4])
table5_2 <- prop5_2/total5_2 * 100

prop5_3 <- svytable(~ Q7G, design = milconf_design)[1:4]
total5_3 <- sum(prop5_3[1:4])
table5_3 <- prop5_3/total5_3 * 100

prop5_4 <- svytable(~ Q7H, design = milconf_design)[1:4]
total5_4 <- sum(prop5_4[1:4])
table5_4 <- prop5_4/total5_4 * 100

table5 <- data.frame(label = c("Active Duty", "Retired", "Not Sure", "Never Heard Of"),
                     gofo1 = table5_1,
                     gofo2 = table5_2,
                     gofo3 = table5_3,
                     gofo4 = table5_4)

colnames(table5) <- c("", "McMaster", "Goldfein", "Dunford", "Milley")
tab5 <- xtable(table5)
align(tab5) <- "rrcccc"
digits(tab5) <- c(0,0,1,1,1,1)
```

```{r echo = FALSE, results = "asis"}
print(tab5, comment = FALSE, size = "\\large", include.rownames = FALSE)
```

```{r echo = FALSE}
# table 7
prop7 <- svytable(~ Q19AF_r1, design = milconf_design)
total7 <- sum(prop7[1:5])
table7 <- rev(prop7/total7 * 100)
table7 <- as.data.frame(table7)

table7$Q19AF_r1 <- c("Strongly agree", "Agree", "Neither agree nor disagree", "Disagree", "Strongly disagree")
colnames(table7) <- c("", "Frequency (%)")
tab7 <- xtable(table7)
align(tab7) <- "rrc"
digits(tab7) <- c(0,0,1)
```

```{r echo = FALSE, results = "asis"}
print(tab7, comment = FALSE, size = "\\large", include.rownames = FALSE)
```